<?php
class OrderAction extends StudyBaseAction
{
	/**
	 * 订单列表
	 */
	public function orderList()
	{
		$order = M('User_appointment');
		if($_SESSION['user']['type'] == '2'){
			$where['cen.user_id'] = array('eq',(int)$_SESSION['user']['id']);
		}
		if(isset($_POST['name']) && $_POST['name']!=null){
			$where['cen.name'] = array('like',"%{$_POST['name']}%");
		}
		if(isset($_POST['course_name']) && $_POST['course_name']!=null){
			$where['cou.course_name'] = array('like',"%{$_POST['course_name']}%");
		}
		if(isset($_POST['order_status']) && $_POST['order_status']!=null){
			$where['s_user_appointment.order_status'] = array('eq',"{$_POST['order_status']}");
		}
		import('ORG.Util.Page');
		$count = $order->where($where)->count();// 查询满足要求的总记录数
		$page = new Page($count,10);
		$limit = $page->firstRow . ',' . $page->listRows;
		$list = $order->field('s_user_appointment.*,cen.name as center_name,cou.course_name as course_name,u.username')->where($where)
		->join("left JOIN s_course cou on s_user_appointment.course_id = cou.id
		left JOIN s_center cen on cou.center_id = cen.id 
		left join s_user u on u.id = s_user_appointment.user_id")->limit($limit)->order("s_user_appointment.create_time desc")->select();
		$show = $page->show();
		$this->assign('page',$show);
		$this->assign('name',$_POST['name']);
		$this->assign('course_name',$_POST['course_name']);
		$this->assign('order_status',$_POST['order_status']);
		$this->assign('list',$list);
		$p = $_GET['p'];
		if(empty($p)){
			$p = 1;
		}
		$this->assign('p',$p);
		$this->display('Order:orderList');
	}
	/**
	 * 查看
	 */
	public function orderLook()
	{
		$form = M('User_appointment');
		$where["s_user_appointment.id"] = $_GET['id'];
		$list = $form->field('s_user_appointment.*,cen.name as center_name,cou.course_name as course_name,u.username')->where($where)
		->join("left JOIN s_course cou on s_user_appointment.course_id = cou.id
		left JOIN s_center cen on cou.center_id = cen.id 
		left join s_user u on u.id = s_user_appointment.user_id")->find();
		$course_i['course_id'] = $form->where($where)->getField('course_id');
		$center_i['center_id'] = $form->join('left join s_course cc on cc.id = s_user_appointment.course_id')->where($where)->getField('cc.center_id');

		$course_game = M("Course_image");
		$courseImage = $course_game->where($course_i)->select();
		$center_game = M("Center_image");
		$centerImage = $center_game->where($center_i)->select();

		$this->assign("list",$list);
		$this->assign("courseImage",$courseImage);
		$this->assign("centerImage",$centerImage);
		$this->display();
	}

	/**
	 * 修改状态
	 */
	public function yifuk()
	{
		$game = M("User_appointment");
		$where['id']=$_GET['id'];
		$data['order_status']="已完成";
		$game->where($where)->save($data);
		$p = $_GET['p'];
		$this->redirect('Order:orderList?p='.$p);
	}

}
?>